package com.jf3q.front.controller;

import com.jf3q.common.domain.EduMember;
import com.jf3q.common.vo.ResultVo;
import com.jf3q.front.service.MemberService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/geren")
@Tag(name = "会员控制层")
public class GerenController {
    @Autowired
    MemberService memberService;

    @Operation(summary = "查看个人信息")
    @GetMapping("/getList/{mid}")
    public ResultVo getList(@PathVariable String mid){
        EduMember eduMember=memberService.getById(mid);
        return ResultVo.success("",eduMember);
    }

    @Operation(summary = "修改个人信息")
    @PostMapping("/saveOrUpdate")
    public ResultVo saveOrUpdate(@RequestBody EduMember eduMemberVo){
        try {

            memberService.saveOrUpdate(eduMemberVo);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return ResultVo.success("",null);
    }

    @Operation(summary = "修改密码")
    @PostMapping("/saveOrUpdateMember")
    public ResultVo saveOrUpdateMember(@RequestBody EduMember eduMemberVo){
        if (memberService.saveOrUpdateMember(eduMemberVo)) {
            return ResultVo.success();
        } else {
            return ResultVo.error();
        }
    }

    @Operation(summary = "判断原密码")
    @PostMapping("/updateMember")
    public ResultVo updateMember(@RequestBody EduMember eduMemberVo){
        if (!memberService.updateMember(eduMemberVo)) {
            return ResultVo.error("原密码错误");
        }
        return ResultVo.success("原密码正确");
    }
}
